package com.fare.taluo.web.action;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.util.StopWatch.TaskInfo;

import com.dayatang.querychannel.support.Page;
import com.fare.taluo.BaseFdcAction;
import com.fare.taluo.PageComponent;
import com.fare.taluo.application.crawl.TaskTemplateApplication;
import com.fare.taluo.application.plane.channel.SourceApplication;
import com.fare.taluo.application.plane.city.PortApplication;
import com.fare.taluo.auth.security.ContextLoginUser;
import com.fare.taluo.auth.security.LogonUserCertificate;
import com.fare.taluo.core.domain.config.channel.SourceEntity;
import com.fare.taluo.core.domain.config.city.PortEntity;
import com.fare.taluo.util.ExportExcelUitl;
import com.fare.taluo.util.JsonUtil;
import com.fare.taluo.util.StringAndDateAndFileUtil;
import com.fare.taluo.vo.core.PortEntityVO;
import com.fare.taluo.vo.core.SourceEntityVO;
import com.fare.taluo.vo.core.SourceTempVO;
import com.fare.taluo.vo.core.TaskAssignDayEntityVO;
import com.fare.taluo.vo.core.TaskInfoEntityVO;
import com.fare.taluo.vo.core.TaskInfoEntityVOVO;
import com.opensymphony.xwork2.ActionContext;
 
/**
 * 
 * @author zhuguohong
 * 
 *         2012-9-26 下午8:02:47
 */
@Controller("taskInfoAction")
@Scope("prototype")
public class TaskInfoAction extends BaseFdcAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5421599490102468629L;
	private int pageNum;// 页码
	private int totalCount;// 总记录数
	private int pageCount;// 总页数
	private int cpage = 1;// 当前页
	private List<Integer> pageList;// 页码列表
	private String mes = "a";// 提示信息
	private String act;// 操作
	private String taskId;
	private String query;// 查询字符串，分页用
	private String depCity;// 出发站
	private String arrCity;// 到达站
	private String source;// 渠道
	private String active;// 是否可用
	private String status ;
	private TaskInfo taskInfo;
    private	int formDate = 0,toDate = 0;
	private Date grabTime;
	private String queryflag;
    private String checkboxs;
	private List<PortEntity> portList;
	private List<SourceEntity> sourceList;
	private List<TaskInfo> taskList;
	private String isUpdate;
	private String message;//网页的提示信息
	private String hfromCity;
	private String htoCity;
	private String assignList;
	
	
	//-------------liangjiajun
	private Log log = LogFactory.getLog(TaskInfoEntityVO.class);
	@Resource(name="taskInfoApplication")
	private TaskTemplateApplication taskInfoApplication;
	
	@Resource(name="portApplication")
	private PortApplication portApplication;
	@Resource(name="sourceApplication")
	private SourceApplication sourceApplication;

	private List<TaskInfoEntityVO> taskInfoEntityVOList;
	private List<SourceEntityVO>  sourceVOList;
	private List<SourceEntityVO>  sourceLists;
	private List<SourceTempVO> sourceTempList;
	private List<PortEntityVO>  portVOList;
	private PageComponent pageComponent;
	private int currentPageNo;
	private int pageSize;
	private String fromCity; // 航段（从）
	private String toCity; // 航段（到）
	private String fromCityName;
	private String toCityName;
	private String grabChannel; // 渠道
	private String grabChannelId;
	private String allGrabChannel;//多选所有的渠道
	private String frequency; // 抓取频率
	private String validityFromStr;// 抓取开始时间
	private String validityToStr; // 抓取结束时间
	private String remark; // 说明
	private String formDateNumber;
	private String toDateNumber;
	private String fromDateNumberString;
	private String toDateNumberString;
	private String frequenceString;
	private String isReturn;
	private String priority;
	private String returnDateScope;
	private String grabChannel2;
	private String name;
	private Long sourceId;
	private String baseKey;
	private String[] fromArray = null;
	private String[] toArray = null;
	private String[] frequencyArray = null;
	private String idAndGrapScope;
	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		this.priority = priority;
	}

	private String url;
	private String webTyle;// 网站类型
	private String crawlStatus; //1.表示系统从这些网站抓数；0.表示系统不到这些网站抓数。
	private String id;

	
	private File fileText; //上传的文件   
	private String imageFileName; //文件名称    
	private String imageContentType; //文件类型
	
	private String timeGap;//时间差
	
	private String takeoffJson;
	private TaskInfoEntityVO taskInfoVO;

 
	public List<SourceEntityVO> getSourceLists() {
		return sourceLists;
	}
 
	public void setSourceLists(List<SourceEntityVO> sourceLists) {
		this.sourceLists = sourceLists;
	}

	public String getFromCityName() {
		return fromCityName;
	}

	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}

 
	public String getToCityName() {
		return toCityName;
	}
	
 
	public String getStatus() {
		return status;
	}
	
	public String getIdAndGrapScope() {
		return idAndGrapScope;
	}

	public void setIdAndGrapScope(String idAndGrapScope) {
		this.idAndGrapScope = idAndGrapScope;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}

	/**
	 * @return 获取对象
	 */
	public TaskInfoEntityVO getTaskInfoVO() {
		return taskInfoVO;
	}

	/**
	 * @param 设置对象
	 */
	public void setTaskInfoVO(TaskInfoEntityVO taskInfoVO) {
		this.taskInfoVO = taskInfoVO;
	}
 
	/**
	 * 初始化分页信息
	 */
	private void initPage(String grabChannel,String fromCityStr,String toCityStr,int formDate,int toDate,Date validityFrom,int pageNum,int pageSize) {
		/*cpage = pageNum;
		pageList = new ArrayList<Integer>();
		
		if (totalCount % pageSize != 0) {
			pageCount = totalCount / pageSize + 1;
		} else {
			pageCount = totalCount / pageSize;
		}
		for (int i = 1; i <= pageCount; i++) {
			pageList.add(i);
		}*/
		
		try{
			Page<TaskInfoEntityVO> page = taskInfoApplication
					.findByPage(grabChannel, fromCityStr, toCityStr, formDate,toDate,validityFrom, currentPageNo, pageSize);
			/*ruiList = page.getResult();
			if(ruiList == null || ruiList.isEmpty()&& this.status!=null && this.status.equals("query")){
				status = "empty";
			}*/
			pageComponent = PageComponent.getInstance(page);
		}catch (Exception e) {
			status = "selecterror";
			//logger.debug("",e);
		}
		
		
		
	}
	
	//初始化list -liangjiajun
	private void init() throws Exception {
        if (StringAndDateAndFileUtil.checkString(taskId) && StringAndDateAndFileUtil.checkString(act)  && act.equals("update")) {// 修改
        	String[] ids = taskId.split(",");
        	taskInfoVO= taskInfoApplication.findTaskInfoEntityVO(Long.parseLong(ids[0]));
        	//System.out.println(taskInfoVO.getFromCityName());
			 }
		portVOList = portApplication.findAllPortEntityVO();
		sourceVOList = sourceApplication.findAllSourceEntity();
		//initPage(grabChannel, fromCity, toCity, null ,null,null, currentPageNo, pageSize);
		
		///////
	/*	try{
			Page<ReportUploadInfoVO> page = reportDownloadApplication
					.findByPage(query,currentPageNo, pageSize);
			ruiList = page.getResult();
			if(ruiList == null || ruiList.isEmpty()&& this.status!=null && this.status.equals("query")){
				status = "empty";
			}
			pageComponent = PageComponent.getInstance(page);
		}catch (Exception e) {
			status = "selecterror";
			logger.debug("",e);
		}*/
		/////
		
		
		
		
	}
	
	public String addTaskInfoVO() throws Exception {
		init();
		returnPageURL = "/fare/_zqhxsz.jsp";
		return "dispatcher";
	}
	
	public String newAnTaskInfo()throws Exception{
		init();
		assignList="false";
		isUpdate=null;
		returnPageURL = "/fare/_zqhxsz_add.jsp";
		return "dispatcher";
	}
	
	//抓取航空设置 -liangjiajun
	public String addTaskInfo() throws Exception {
		init();
		returnPageURL = "/fare/_zqhxsz.jsp";
		return "dispatcher";
	}

	private static String nangHang="南方航空官网";
	//添加或修改任务 -liangjiajun
	public void editTaskInfo()  {
		Integer grabsope = null;
		Date validityFrom = null;
		Date validityTo = null;
		String taskName = "";
		String grabChannelStr = "";
		String fromCityStr = "";
		String toCityStr = "";

		//获取基本数据
		//==========================================
		// 任务名称
		if(StringAndDateAndFileUtil.checkString(act)  && act.equals("update")){
			fromCity = hfromCity;
			toCity = htoCity;
		}
			
		
		if (StringAndDateAndFileUtil.checkString(fromCity) && StringAndDateAndFileUtil.checkString(toCity)) {
			
			//返回航段
			PortEntityVO vo = portApplication.findPortEntityByCityName(fromCity);
			if(vo != null){
				fromCityStr = vo.getPortCode();
			}
			PortEntityVO vo2 = portApplication.findPortEntityByCityName(toCity);
			if(vo2 != null){
				toCityStr = vo2.getPortCode();
			}
			
			taskName = new StringBuffer().append(fromCityStr).append("+").append(toCityStr).toString();
		}
		
		/*// 航班天数
		if (StringAndDateAndFileUtil.checkString(formDateNumber) && StringAndDateAndFileUtil.checkString(toDateNumber)) {
			grabsope = Integer.parseInt(toDateNumber) - Integer.parseInt(formDateNumber);
		}
		*/
		// 航班抓取时间
		if (StringAndDateAndFileUtil.checkString(validityFromStr) && StringAndDateAndFileUtil.checkString(validityToStr)) {
			try {
				validityFrom = StringAndDateAndFileUtil.formatDateString(validityFromStr, "yyyy-MM-dd");
				validityTo = StringAndDateAndFileUtil.formatDateString(validityToStr,"yyyy-MM-dd");
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		//将小时转为分钟
		if(StringAndDateAndFileUtil.checkString(frequency)&&!frequency.contains(",")){
			Float min=Float.parseFloat(frequency)*60;
			frequency=min.toString();
		}
		
		grabChannelStr = grabChannel;//抓取渠道
		LogonUserCertificate user = ContextLoginUser.getLoginUser();
		
		
		//id存在的情况下为修改
		if (StringAndDateAndFileUtil.checkString(taskId) 
				&& StringAndDateAndFileUtil.checkString(act)  && act.equals("update")) {// 修改
			String[] idArray = null;
			sourceLists = sourceApplication.findAllSourceEntity();
			for (Iterator iterator = sourceLists.iterator(); iterator.hasNext();) {
				SourceEntityVO vo = (SourceEntityVO) iterator.next();
				if(vo.getId().toString().equals(grabChannelId)){
					grabChannelStr=vo.getName();
					baseKey = vo.getHbaseKey();
				}
			}				   
			System.out.println(idAndGrapScope);
			String[] idAndGrapScopeArr = idAndGrapScope.split(",");
			
			
			if(taskId.contains(",")){
				idArray = taskId.split(",");
			}else{
				idArray = new String[1];
				idArray[0] = taskId;
			}
			if(idArray != null){
				for (int i = 0; i < idArray.length; i++) {
					taskId = idArray[i];
					if(StringAndDateAndFileUtil.checkString(taskId)){
						/*for (String string : idAndGrapScopeArr) {
							if(StringAndDateAndFileUtil.checkString(string)){
								String[] temp = string.split("_");
								if(taskId.equals(temp[0])){
									formDateNumber = temp[1];
									toDateNumber = temp[2];
									frequency = temp[3];
								}
							}
							
						}*/
						if(com.fare.taluo.util.StringUtils.isNotEmpty(fromDateNumberString)&&
								   com.fare.taluo.util.StringUtils.isNotEmpty(toDateNumberString)&&
								   com.fare.taluo.util.StringUtils.isNotEmpty(frequenceString)){
									
									fromArray = fromDateNumberString.split(";");
									toArray = toDateNumberString.split(";");
									frequencyArray = frequenceString.split(";");
									
								}
								
								
									String formDateNumber = fromArray[i];
									String toDateNumber = toArray[i];
									
									if(StringAndDateAndFileUtil.checkString(frequencyArray[i])){
										Float min=Float.parseFloat(frequencyArray[i])*60;
										frequency=min.toString();
									} 
									
									try {
									    int returnDate = 0;
										if(StringAndDateAndFileUtil.checkString(returnDateScope)){
											returnDate = Integer.parseInt(returnDateScope);
										}
										if("1".equals(isReturn)){
											List<TaskAssignDayEntityVO> assignDayList =new ArrayList<TaskAssignDayEntityVO>();
											for (int j = 0; j < fromArray.length; j++) {
												TaskAssignDayEntityVO assignVo= new TaskAssignDayEntityVO();
												assignVo.setAssignFlightDay(Integer.parseInt(fromArray[j]));
												assignVo.setAssignRoundDay(Integer.parseInt(toArray[j]));
												assignDayList.add(assignVo);
											}
											if(StringAndDateAndFileUtil.checkString(frequencyArray[0])){
												Float min=Float.parseFloat(frequencyArray[0])*60;
												frequency=min.toString();
											}
											TaskInfoEntityVO taskVO =new TaskInfoEntityVO();
											taskVO.setAssignDayList(assignDayList);
											taskVO.setTaskName(taskName);
											taskVO.setGrabChannel(grabChannelStr);
											taskVO.setFromCity(fromCityStr);
											taskVO.setFromCityName(fromCity);
											taskVO.setToCity(toCityStr);
											taskVO.setToCityName(toCity);
											taskVO.setValidityFrom(validityFrom);
											taskVO.setValidityTo(validityTo);
											taskVO.setGrabsopeBegin(0);//返程的默认为0
											taskVO.setGrabsopeEnd(30);//返程的默认为30;
											taskVO.setFrequency(frequency);
											taskVO.setRemark(remark);
											taskVO.setIsReturn(isReturn);
											taskVO.setReturnDateScope(0);//返程不用这个属性了 
											taskVO.setStatus(1);
											taskVO.setPriority(Integer.parseInt(priority));
											taskVO.setGrabChannelId(Long.parseLong(grabChannelId));
											taskVO.setAttachHbaseKey(baseKey);
											//taskVO.setId(Long.parseLong(taskId));
											try {
												taskInfoApplication.deleteTaskInfoEntity(Long.parseLong(taskId));
												taskInfoApplication.save(taskVO);
		
											} catch (Exception e) {
												if(e.getMessage().equalsIgnoreCase("机场区域信息为空")){
													e.printStackTrace();
												//	buffer.append("\\n【 "+gcStr+" 】保存失败。机场区域信息为空,请设置！");
												}else{
													e.printStackTrace();
												}
											}
										}else{
											//TaskInfoEntityVO taskInfoVO = taskInfoApplication.findTaskInfoEntityVO(Long.parseLong(taskId));
											taskInfoApplication.saveOrUpdateTaskInfoEntity(taskName,grabChannelStr,fromCityStr,fromCity,
													toCityStr,toCity,validityFrom,validityTo,Integer.parseInt(formDateNumber),Integer.parseInt(toDateNumber),
													frequency,remark,isReturn,returnDate,"1",null,new Date(),
													Integer.parseInt(priority),(taskId!=null&&!"".equals(taskId))?Long.parseLong(taskId):0,Long.parseLong(grabChannelId),baseKey);
										}
										
									} catch (Exception e) {
										e.printStackTrace();
									}
									this.mes = "修改任务成功！";
									formDate = -1;
							    	toDate = -1;
									
								
						
					}
					
				}
			}		
		}else{//新保存数据	
			//=====================================================================================
			StringBuffer buffer=new StringBuffer();
			String[] sourceInfos=allGrabChannel.split(";");
			for(String info:sourceInfos){
				String[] strs=info.split(",");
				Long id=Long.parseLong(strs[0]);
				String key=strs[1];
				String gcStr=strs[2];
				/*//判断是否存在数据
				TaskInfoEntityVO vo=taskInfoApplication.findTaskInfoEntityVo(
						gcStr, fromCityStr, toCityStr, validityFrom, validityTo, 
						Integer.parseInt(formDateNumber),Integer.parseInt(toDateNumber));
				if(vo!=null){//不为空，则不需要再添加数据
					buffer.append("\\n【 "+gcStr+" 】数据已存在！无需再次添加");
					continue;
				}*/
				
				if(com.fare.taluo.util.StringUtils.isNotEmpty(fromDateNumberString)&&
				   com.fare.taluo.util.StringUtils.isNotEmpty(toDateNumberString)&&
				   com.fare.taluo.util.StringUtils.isNotEmpty(frequenceString)){
					
					fromArray = fromDateNumberString.split(";");
					toArray = toDateNumberString.split(";");
					frequencyArray = frequenceString.split(";");
					
				}
				if("1".equals(isReturn)){
					List<TaskAssignDayEntityVO> assignDayList =new ArrayList<TaskAssignDayEntityVO>();
					for (int i = 0; i < fromArray.length; i++) {
						TaskAssignDayEntityVO assignVo= new TaskAssignDayEntityVO();
						assignVo.setAssignFlightDay(Integer.parseInt(fromArray[i]));
						assignVo.setAssignRoundDay(Integer.parseInt(toArray[i]));
						assignDayList.add(assignVo);
					}
					if(StringAndDateAndFileUtil.checkString(frequencyArray[0])){
						Float min=Float.parseFloat(frequencyArray[0])*60;
						frequency=min.toString();
					}
					TaskInfoEntityVO taskVO =new TaskInfoEntityVO();
					taskVO.setAssignDayList(assignDayList);
					taskVO.setTaskName(taskName);
					taskVO.setGrabChannel(gcStr);
					taskVO.setFromCity(fromCityStr);
					taskVO.setFromCityName(fromCity);
					taskVO.setToCity(toCityStr);
					taskVO.setToCityName(toCity);
					taskVO.setValidityFrom(validityFrom);
					taskVO.setValidityTo(validityTo);
					taskVO.setGrabsopeBegin(0);//返程的默认为0
					taskVO.setGrabsopeEnd(30);//返程的默认为30;
					taskVO.setFrequency(frequency);
					taskVO.setRemark(remark);
					taskVO.setIsReturn(isReturn);
					taskVO.setReturnDateScope(0);//返程不用这个属性了 
					taskVO.setStatus(1);
					taskVO.setPriority(Integer.parseInt(priority));
					taskVO.setGrabChannelId(id);
					taskVO.setAttachHbaseKey(key);
					try {
						taskInfoApplication.save(taskVO);
					} catch (Exception e) {
						if(e.getMessage().equalsIgnoreCase("机场区域信息为空")){
							e.printStackTrace();
							buffer.append("\\n【 "+gcStr+" 】保存失败。机场区域信息为空,请设置！");
						}else{
							e.printStackTrace();
						}
					}
				}else{
					for (int i = 0; i < fromArray.length; i++) {
						String formDateNumber = fromArray[i];
						String toDateNumber = toArray[i];
						
						if(StringAndDateAndFileUtil.checkString(frequencyArray[i])){
							Float min=Float.parseFloat(frequencyArray[i])*60;
							frequency=min.toString();
						} 
						if(returnDateScope!=null || "".equals(returnDateScope)  ){
							returnDateScope="0";
						}
						
						try {
							taskInfoApplication.saveOrUpdateTaskInfoEntity(taskName,gcStr,fromCityStr,fromCity,
									toCityStr,toCity,validityFrom,validityTo,Integer.parseInt(formDateNumber),Integer.parseInt(toDateNumber),
									frequency,remark,isReturn,Integer.parseInt(returnDateScope),"1",null,new Date(),
									Integer.parseInt(priority),0,id,key);
							buffer.append("\\n【 "+gcStr+" 】数据保存成功！");
						}  catch (Exception e) {
							if(e.getMessage().equalsIgnoreCase("机场区域信息为空")){
								e.printStackTrace();
								buffer.append("\\n【 "+gcStr+" 】保存失败。机场区域信息为空,请设置！");
							}else{
								e.printStackTrace();
							}
						}
						
					}
				}
				
			}
			if(sourceInfos.length>1){
				this.grabChannel="";
			}
			if(!buffer.toString().equals("")){
				this.mes="本次操作提示："+"\\n"+buffer.toString();
			}
			System.out.println(buffer.toString());

		}
		//return showTaskInfoList();
		response.setContentType("text/html");
		try {
			response.getWriter().write("OK");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	

	/**
	 * @return the queryflag
	 */
	public String getQueryflag() {
		return queryflag;
	}

	/**
	 * @param queryflag the queryflag to set
	 */
	public void setQueryflag(String queryflag) {
		this.queryflag = queryflag;
	}
	

	//查询显示任务列表 -liangjiajun
	public String showTaskInfoList()  {
		try {
			init();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 航班天数
		Integer grabsope = 0;
		String fromCityStr = "";
		String toCityStr = "";
		
		/*if (StringAndDateAndFileUtil.checkString(formDateNumber) && StringAndDateAndFileUtil.checkString(toDateNumber)) {
			grabsope = Integer.parseInt(toDateNumber) - Integer.parseInt(formDateNumber);
		}*/
//		if (formDateNumber==null ||formDateNumber.trim().equals("")) {
//			formDateNumber="0";
//		}
//		if ( toDateNumber==null||toDateNumber.trim().equals("")) {
//			toDateNumber="0";
//		}
		
		if(fromCity==null||fromCity.trim().equals("中文/拼音")){
			fromCity = "";
		}
		if(toCity==null||toCity.trim().equals("中文/拼音")){
			toCity = "";
		}
		
		if (StringAndDateAndFileUtil.checkString(fromCity)) {
			//返回航段
			PortEntityVO vo = portApplication.findPortEntityByCityName(fromCity);
			if(vo != null){
				fromCityStr = vo.getPortCode();
			}
		}
		if (StringAndDateAndFileUtil.checkString(toCity)) {
			//返回航段
			PortEntityVO vo2 = portApplication.findPortEntityByCityName(toCity);
			if(vo2 != null){
				toCityStr = vo2.getPortCode();
			}
		}
		if(StringAndDateAndFileUtil.checkString(grabChannel2)){
			grabChannel = grabChannel2;
			if(grabChannel2.equals("all")){
				grabChannel=null;
			}
			
		}else{
			if(StringAndDateAndFileUtil.checkString(grabChannel)){
				grabChannel2 = grabChannel;
			}
		}
		
		
		if(currentPageNo == 0){
			currentPageNo = 1;
		}
		if(pageSize == 0){
			pageSize = 10;
		}
		
		System.out.println("currentPageNo=="+currentPageNo+"pageSize=="+pageSize);
		
		if(StringAndDateAndFileUtil.checkString(act)  && act.equals("update")){
			formDateNumber ="";
			toDateNumber="";
			formDate = -1;
			toDate = -1;
		}else{
			
			if(StringUtils.isEmpty(formDateNumber)){
				formDate = -1;
			}else if(formDateNumber.contains(",")){
				
				
				//formDateNumber = formDateNumber.split(",")[0];
				formDate = Integer.parseInt(formDateNumber.split(",")[0]);
			}else {
				formDate = Integer.parseInt(formDateNumber);
			}
			if(StringUtils.isEmpty(toDateNumber)){
				toDate = -1;
			}else if(toDateNumber.contains(",")){
				String[] array = toDateNumber.split(",");
				//toDateNumber = array[array.length-1];
				toDate = Integer.parseInt(array[array.length-1].trim());
			}else{
				toDate = Integer.parseInt(toDateNumber);
			}
		}
		
		
		// 航班抓取时间
		Date validityFrom = null;
				if (StringAndDateAndFileUtil.checkString(validityFromStr) ) {
					try {
						validityFrom = StringAndDateAndFileUtil.formatDateString(validityFromStr, "yyyy-MM-dd");
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
		
	/*	if(null!=fromArray&& fromArray.length>0){
			
	
		}else{
			taskInfoEntityVOList = taskInfoApplication.findTaskInfoEntityVOCriteriaList(grabChannel, fromCityStr, toCityStr, formDate,toDate,validityFrom, currentPageNo, pageSize);
			totalCount = taskInfoApplication.countTaskInfoEntityCriteria(grabChannel, fromCityStr, toCityStr,validityFrom, formDate,toDate);
		}*/
				
				
	    if(formDateNumber.contains(",")){
	    	formDateNumber = "";//formDateNumber.split(",")[0];
	    	String[] array = toDateNumber.split(",");
			toDateNumber = "";//array[array.length-1];
	    	formDate = -1;
	    	toDate = -1;
	    	taskInfoEntityVOList = taskInfoApplication.findTaskInfoEntityVOCriteriaList(grabChannel, fromCityStr, toCityStr, formDate,toDate,validityFrom, currentPageNo, pageSize);
	    }else{
	    	taskInfoEntityVOList = taskInfoApplication.findTaskInfoEntityVOCriteriaList(grabChannel, fromCityStr, toCityStr, formDate,toDate,validityFrom, currentPageNo, pageSize);
	    }
		//合并taskInfoEntityVOList
	    taskInfoEntityVOList=  merger(taskInfoEntityVOList);
	    
		totalCount = taskInfoApplication.countTaskInfoEntityCriteria(grabChannel, fromCityStr, toCityStr,validityFrom, formDate,toDate);
		//initPage(totalCount);
//		
		initPage(grabChannel, fromCityStr, toCityStr, formDate,toDate,validityFrom, currentPageNo, pageSize);
		
		totalCount = 0;
//		if(null != taskInfoEntityVOList){
//			totalCount = taskInfoEntityVOList.size();
//		}
//		initPage(totalCount);
		
		//为了导出时，使用。
		ActionContext.getContext().put("formDateNumberStrs", formDateNumber);
		ActionContext.getContext().put("toDateNumberStrs", toDateNumber);
		ActionContext.getContext().put("toDateNumber", toDateNumber);
		ActionContext.getContext().put("grabChannel2", grabChannel2);
		ActionContext.getContext().put("fromCity", fromCity);
		ActionContext.getContext().put("toCity", toCity);
		
		if(taskInfoEntityVOList == null || taskInfoEntityVOList.isEmpty()){
			status = "taskInfonotfound";
		}
		
		
		returnPageURL = "/fare/_zqhxsz.jsp";
		return "dispatcher";
	}
	
	private List<TaskInfoEntityVO> merger(List<TaskInfoEntityVO> taskInfoEntityVOList){
		List<TaskInfoEntityVO> tmpList = new ArrayList<TaskInfoEntityVO>();
		tmpList.addAll(taskInfoEntityVOList);
		taskInfoEntityVOList.clear();
		String idAndGrapScope ="";
		for (int i = 0; i < tmpList.size(); i++) {
			TaskInfoEntityVO firstVO = tmpList.get(i);
			String regulation = "";
			regulation = regulation +"未来"+firstVO.getGrabsopeBegin()+"天到"+firstVO.getGrabsopeEnd()+
					"天 频率"+Double.parseDouble(firstVO.getFrequency())/60+ "小时 <br>";
			firstVO.setRegulation(regulation);
			
			idAndGrapScope=firstVO.getId()+"_"+firstVO.getGrabsopeBegin()+"_"+firstVO.getGrabsopeEnd()+"_"+firstVO.getFrequency()+",";
			firstVO.setIdAndGrapScope(idAndGrapScope);
			firstVO.setIdString(firstVO.getId()+",");
			for (int j = 0; j < tmpList.size(); j++) {
				if(i!=j){
					TaskInfoEntityVO secondVO = tmpList.get(j);
					if(firstVO.getFromCity().equals(secondVO.getFromCity())
							&& firstVO.getToCity().equals(secondVO.getToCity())
							&& firstVO.getGrabChannel().equals(secondVO.getGrabChannel())){
						regulation = regulation +"未来"+ secondVO.getGrabsopeBegin()+"天到"+secondVO.getGrabsopeEnd()+
								"天 频率"+Double.parseDouble(secondVO.getFrequency())/60+ "小时 <br>";
						firstVO.setRegulation(regulation);			
						firstVO.setIdString(firstVO.getIdString()+secondVO.getId()+",");
						idAndGrapScope = idAndGrapScope + secondVO.getId()+"_"+secondVO.getGrabsopeBegin()+"_"+secondVO.getGrabsopeEnd()+"_"+secondVO.getFrequency()+",";
						firstVO.setIdAndGrapScope(idAndGrapScope);
					}
				}
				
			}
			
		}	
		
		//去除重复
		Map<String, TaskInfoEntityVO> map = new HashMap<String, TaskInfoEntityVO>();
		for (int i = 0; i < tmpList.size(); i++) {
			String key = tmpList.get(i).getFromCity()+tmpList.get(i).getToCity()+tmpList.get(i).getGrabChannel();
			map.put(key, tmpList.get(i));
		}
		tmpList.clear();
		Set set = map.entrySet() ;
		Iterator it = map.entrySet().iterator();
		while(it.hasNext()){
	    Entry entry = (java.util.Map.Entry)it.next();
		tmpList.add((TaskInfoEntityVO) entry.getValue()); //返回与此项对应的值
		} 	
		return tmpList;
	}
	
	//删除抓取网站 -liangjiajun
	public void deleteTaskInfoEntity()throws Exception {
		
		
		
		//单个删除
		if (StringAndDateAndFileUtil.checkString(taskId)) {
			if(taskId.contains(",")){
				String[] idArray = taskId.split(",");
				for (int i = 0; i < idArray.length; i++) {
					if(StringAndDateAndFileUtil.checkString(idArray[i])){
						taskInfoApplication.deleteTaskInfoEntity(Long.parseLong(idArray[i]));
					}
				}
				
			}
			
		}
		
		//批量删除
		//String ids[] = request.getParameterValues("checkboxs");
		if(StringAndDateAndFileUtil.checkString(checkboxs)){
			String ids[] = checkboxs.split(",");
			if(ids != null){
				if(ids.length >0){
					for (int i = 0; i < ids.length; i++) {
						if(StringAndDateAndFileUtil.checkString(ids[i])){
							taskInfoApplication.deleteTaskInfoEntity(Long.parseLong(ids[i]));
						}
						
						
					}
				}
			}
		}
		
		//else{
//			this.mes = "删除失败，请至少选择一条数据！";
//			return "";
//		}
		this.mes = "删除成功！";
		response.getWriter().write("OK");
		//return showTaskInfoList();
	}
	
	
	public String modifyTaskInfoEntity() throws NumberFormatException, Exception{
		try {
			init();
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(grabChannelId);
		if(StringAndDateAndFileUtil.checkString(taskId)){
			if(taskId.contains(",")){
			   String[] idArray = taskId.split(",");
			   List<TaskInfoEntityVO> voList = new ArrayList<TaskInfoEntityVO>();
			   for (int i = 0; i < idArray.length; i++) {
				   if(StringAndDateAndFileUtil.checkString(idArray[i])){
					   voList.add(taskInfoApplication.findTaskInfoEntityVO(Long.parseLong(idArray[i])));
				   }
				   
			   }
			   
			   TaskInfoEntityVO temp = new TaskInfoEntityVO();
			   String grabBegin = "";
			   String grabEnd = "";
			   String frequenceString ="";
			   for (TaskInfoEntityVO taskInfoEntityVO : voList) {
				   grabBegin = grabBegin + taskInfoEntityVO.getGrabsopeBegin()+",";
				   grabEnd = grabEnd + taskInfoEntityVO.getGrabsopeEnd()+",";
				   frequenceString = frequenceString + taskInfoEntityVO.getFrequency()+",";
			   }
			   temp.setArea(voList.get(0).getArea());
			   temp.setAreaCode(voList.get(0).getAreaCode());
			   temp.setFrequency(voList.get(0).getFrequency());
			   temp.setFromCity(voList.get(0).getFromCity());
			   temp.setFromCityName(voList.get(0).getFromCityName());
			   temp.setGrabBegin(voList.get(0).getGrabBegin());
			   temp.setGrabChannel(voList.get(0).getGrabChannel());
			   temp.setGrabEnd(voList.get(0).getGrabEnd());
			   temp.setGrabsopeBegin(voList.get(0).getGrabsopeBegin());
			   temp.setGrabsopeEnd(voList.get(0).getGrabsopeEnd());
			   temp.setIsReturn(voList.get(0).getIsReturn());
			   temp.setPriority(voList.get(0).getPriority());
			   temp.setProvince(voList.get(0).getProvince());
			   temp.setProvinceCode(voList.get(0).getProvinceCode());
			   temp.setRegulation(voList.get(0).getRegulation());
			   temp.setRemark(voList.get(0).getRemark());
			   temp.setTaskName(voList.get(0).getTaskName());
			   temp.setToCity(voList.get(0).getToCity());
			   temp.setToCityName(voList.get(0).getToCityName());
			   temp.setValidityFrom(voList.get(0).getValidityFrom());
			   temp.setValidityTo(voList.get(0).getValidityTo());
			   temp.setIdString(taskId);
			   temp.setAssignDayList(voList.get(0).getAssignDayList());
			   temp.setGrabBegin(grabBegin);
			   temp.setGrabEnd(grabEnd);
			   temp.setFrequenceString(frequenceString);
			   taskInfoVO = temp;
			   JSONObject tjson = new JSONObject();
			   tjson.put("assignList", taskInfoVO.getAssignDayList());
			   assignList =tjson.toString();
			   act="update"; 
			   grabChannelId=temp.getGrabChannelId().toString();
			}else{
				taskInfoVO = taskInfoApplication.findTaskInfoEntityVO(Long.parseLong(taskId));
				taskInfoVO.setIdString(taskId);
				JSONObject tjson = new JSONObject();
				tjson.put("assignList", taskInfoVO.getAssignDayList());
				assignList =tjson.toString();
				 act="update"; 
				 grabChannelId=taskInfoVO.getGrabChannelId().toString();
			}
		}
				
		
		isUpdate = "yes";
		returnPageURL = "/fare/_zqhxsz_add.jsp";
		return "dispatcher";
	}
	
	
	
	//导出Excul -liangjiajun
	public String exculTaskInfo() throws Exception {
		
		// 航班天数
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); 
		
		String grabChannel = request.getParameter("grabChannel2H");
		String fromCity = request.getParameter("fromCityH");
		String toCity = request.getParameter("toCityH");
		String formDateNumber = request.getParameter("formDateNumberStrsH");
		String toDateNumber = request.getParameter("toDateNumberStrsH");
		
		Integer grabsope = 0;
		if (StringAndDateAndFileUtil.checkString(formDateNumber) && StringAndDateAndFileUtil.checkString(toDateNumber)) {
			grabsope = Integer.parseInt(toDateNumber) - Integer.parseInt(formDateNumber);
		}
		
		if(fromCity.equals("中文/拼音")){
			fromCity = "";
		}
		if(toCity.equals("中文/拼音")){
			toCity = "";
		}
		if (StringAndDateAndFileUtil.checkString(fromCity) && StringAndDateAndFileUtil.checkString(toCity)) {
			
			//返回航段
			PortEntityVO vo = portApplication.findPortEntityByCityName(fromCity);
			if(vo != null){
				fromCity = vo.getPortCode();
			}
			PortEntityVO vo2 = portApplication.findPortEntityByCityName(toCity);
			if(vo2 != null){
				toCity = vo2.getPortCode();
			}
		}
		
		//导出查询的数据
		List<TaskInfoEntityVOVO> voList = new ArrayList<TaskInfoEntityVOVO>();
		voList = taskInfoApplication.findTaskInfoByConsdions(grabChannel, fromCity, toCity, Integer.parseInt(formDateNumber),Integer.parseInt(toDateNumber));

		// 输出流参数
		String file = "d:/抓取航线查询结果_"+StringAndDateAndFileUtil.formatDate(new Date(), "yyyy-MM-dd")+".xls";// 设置输出流
		FileOutputStream out = null;
		try {
			out = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			e = null;
		}
		// 列头参数名称
		String[] str = { "ID", "航段", "网站名称", "航班日期", "开始日期", "结束日期","抓取频率(小时/次)","操作人","操作时间" };

		// 标题参数
		String title = "1";

		// 时间格式参数
		String fomatStr = "yyyy-MM-dd";
		
		ExportExcelUitl.exportExcel(title, str, voList, out, fomatStr);
		
		this.mes = "导出成功！";
		returnPageURL = "/fare/_zqhxsz.jsp";
		return "dispatcher";
	}
	
	//导入Excul数据 -liangjiajun
	public String impExculTaskInfo() throws Exception {        
		String taskName = "";
		String grabChannel = "";
		String frequency = "";
		int grabsope = 0;
		Date validityFrom = null;
		Date validityTo = null;
		Date userCreateTime = null;
		String fromCityStr = "";
		String toCityStr = "";
		String assignDay="";
		String assignFrightDay="";
		
		String realpath = ServletActionContext.getServletContext().getRealPath("/upload");    
		if (fileText != null) {            
			imageFileName = new String(imageFileName.getBytes("iso-8859-1"),"utf-8");
			File savefile = new File(new File(realpath), imageFileName);            
			if (!savefile.getParentFile().exists()){
				savefile.getParentFile().mkdirs();            
			}                
			FileUtils.copyFile(fileText, savefile);  
			
			List<String> list = new ArrayList<String>();
			
			ExportExcelUitl.readExcel(fileText,list);
			
			//保存在数据库中。
			for (String string : list) {
					String[] column = string.split("_");//每行每个字段
					for (int j = 0; j < column.length; j++) {
						if(StringAndDateAndFileUtil.checkString(column[1]) &&  !"a".equals(column[1])){
							taskName = column[1];
							String[] str3 = taskName.split("\\+");
							fromCityStr = str3[0];
							toCityStr = str3[1];
						}
						grabChannel = column[2];
						if(StringAndDateAndFileUtil.checkString(column[3]) && !"a".equals(column[3])){
							grabsope = Integer.parseInt(column[3]);
						}
						if(StringAndDateAndFileUtil.checkString(column[4]) && !"a".equals(column[4])){
							validityFrom = StringAndDateAndFileUtil.formatDateString(column[4],"yyyy-MM-dd");
						}
						if(StringAndDateAndFileUtil.checkString(column[5]) && !"a".equals(column[5])){
							validityTo = StringAndDateAndFileUtil.formatDateString(column[5],"yyyy-MM-dd");
						}
						frequency = column[6];
						String userName = column[7];
						
						if(StringAndDateAndFileUtil.checkString(column[8]) && !"a".equals(column[8])){
							userCreateTime = StringAndDateAndFileUtil.formatDateString(column[8],"yyyy-MM-dd");
						}
						
					}
					//保存
//					taskInfoApplication.saveOrUpdateTaskInfoEntity(taskName,grabChannel,fromCityStr,
//							toCityStr,validityFrom,validityTo,grabsope,frequency,remark,user,userCreateTime);
					
			}
			this.mes = "导入成功！"; 
			
			//导入完后，把文件删除
			StringAndDateAndFileUtil.deleteFile(realpath + "\\" + imageFileName);
			return showTaskInfoList(); 
		}       
		 return null;
	}
	
	//抓取网站设置
	//抓取网站设置Link -liangjiajun
	public String toSourceLink() throws Exception {
		returnPageURL = "/fare/_zqwzsz.jsp";
		return "dispatcher";
	}
	
	private String sorttype;//排序类型
	public String getSorttype() {
		return sorttype;
	}

	public void setSorttype(String sorttype) {
		this.sorttype = sorttype;
	}

	//查询 -liangjiajun
	public String findListSource()throws Exception {
		
//		if(currentPageNo == 0){
//			currentPageNo = 1;
//		}
//		if(pageSize == 0 || pageSize == 5){
//			pageSize = 5;
//		}else{
//			currentPageNo = 1;//当显示数量改变后，需要把页数设置为1，否则有问题。
//		}
//		sourceLists = sourceApplication.findSourceEntityListByConditions("","","","",1,1000);
//		if(StringUtils.isNotBlank(this.url)){
//			this.url=this.url.replace(" ", "");
//		}
		sourceVOList = sourceApplication.findAllSourceEntity();
		//.findSourceEntityListByConditions(name, this.url, webTyle,sorttype,currentPageNo, pageSize);
		//totalCount = sourceApplication.getSourceEntityCount(name, this.url, webTyle);
		//this.initPage(totalCount);

		if(sourceVOList==null||sourceVOList.isEmpty()||sourceVOList.size()==0){//对查询不到的结果进行提示
			message="对不起,没有相关数据";
			request.setAttribute(message, message);
		}
		Collections.sort(sourceVOList);
		returnPageURL = "/fare/_zqwzsz.jsp";
		return "dispatcher";
	}
	
	//更新 -liangjiajun
	public void ajaxUpdateSource()throws Exception {
		if(StringAndDateAndFileUtil.checkString(crawlStatus) && StringAndDateAndFileUtil.checkString(id)){
			//User user = getLoginUser();
			sourceApplication.updateSourceEntity(Long.parseLong(id), Integer.parseInt(crawlStatus),null);
			response.getWriter().print("ok");
		}
	}

	public Date getGrabTime() {
		return grabTime;
	}

	public void setGrabTime(Date grabTime) {
		this.grabTime = grabTime;
	}

	public int getcurrentPageNo() {
		return currentPageNo;
	}

	public void setcurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getCpage() {
		return cpage;
	}

	public void setCpage(int cpage) {
		this.cpage = cpage;
	}

	public String getMes() {
		return mes;
	}

	public void setMes(String mes) {
		this.mes = mes;
	}

	public List<Integer> getPageList() {
		return pageList;
	}

	public void setPageList(List<Integer> pageList) {
		this.pageList = pageList;
	}

	public String getAct() {
		return act;
	}

	public void setAct(String act) {
		this.act = act;
	}

	public TaskInfo getTaskInfo() {
		return taskInfo;
	}

	public String getTaskId() {
		return taskId;
	}

	public void setTaskId(String taskId) {
		this.taskId = taskId;
	}

	public void setTaskInfo(TaskInfo taskInfo) {
		this.taskInfo = taskInfo;
	}

	public List<TaskInfo> getTaskList() {
		return taskList;
	}

	public void setTaskList(List<TaskInfo> taskList) {
		this.taskList = taskList;
	}

	public List<PortEntity> getPortList() {
		return portList;
	}

	public void setPortList(List<PortEntity> portList) {
		this.portList = portList;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getDepCity() {
		return depCity;
	}

	public void setDepCity(String depCity) {
		this.depCity = depCity;
	}

	public String getArrCity() {
		return arrCity;
	}

	public void setArrCity(String arrCity) {
		this.arrCity = arrCity;
	}

	public String getActive() {
		return active;
	}

	public void setActive(String active) {
		this.active = active;
	}

	public List<SourceEntity> getSourceList() {
		return sourceList;
	}

	public void setSourceList(List<SourceEntity> sourceList) {
		this.sourceList = sourceList;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getFromCity() {
		return fromCity;
	}

	public void setFromCity(String fromCity) {
		System.out.println(fromCity);
		this.fromCity = fromCity;
	}

	public String getToCity() {
		return toCity;
	}

	public void setToCity(String toCity) {
		System.out.println(toCity);
		this.toCity = toCity;
	}

	public String getGrabChannel() {
		return grabChannel;
	}

	public void setGrabChannel(String grabChannel) {
		this.allGrabChannel=grabChannel;
		this.grabChannel = grabChannel;
		if(StringUtils.isNotEmpty(grabChannel)){
			String [] sourceInfo = grabChannel.split(",");
			if(sourceInfo.length == 3){
				this.sourceId = Long.parseLong(sourceInfo[0]);
				this.baseKey = sourceInfo[1];
				this.grabChannel = sourceInfo[2];
			}
		}
	}

	public String getFrequency() {
		return frequency;
	}

	public void setFrequency(String frequency) {
		this.frequency = frequency;
	}

	public String getValidityFromStr() {
		return validityFromStr;
	}

	public void setValidityFromStr(String validityFromStr) {
		this.validityFromStr = validityFromStr;
	}

	public String getValidityToStr() {
		return validityToStr;
	}

	public void setValidityToStr(String validityToStr) {
		this.validityToStr = validityToStr;
	}

	public String getFormDateNumber() {
		return formDateNumber;
	}

	public void setFormDateNumber(String formDateNumber) {
		this.formDateNumber = formDateNumber;
	}

	public String getToDateNumber() {
		return toDateNumber;
	}

	public void setToDateNumber(String toDateNumber) {
		this.toDateNumber = toDateNumber;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public void setTaskInfoApplication(TaskTemplateApplication taskInfoApplication) {
		this.taskInfoApplication = taskInfoApplication;
	}

	public TaskTemplateApplication getTaskInfoApplication() {
		return taskInfoApplication;
	}

	public List<TaskInfoEntityVO> getTaskInfoEntityVOList() {
		return taskInfoEntityVOList;
	}

	public void setTaskInfoEntityVOList(List<TaskInfoEntityVO> taskInfoEntityVOList) {
		this.taskInfoEntityVOList = taskInfoEntityVOList;
	}

	public String getGrabChannel2() {
		return grabChannel2;
	}

	public void setGrabChannel2(String grabChannel2) {
		this.grabChannel2 = grabChannel2;
	}
	
	public PortApplication getPortApplication() {
		return portApplication;
	}

	public void setPortApplication(PortApplication portApplication) {
		this.portApplication = portApplication;
	}

	public SourceApplication getSourceApplication() {
		return sourceApplication;
	}

	public void setSourceApplication(SourceApplication sourceApplication) {
		this.sourceApplication = sourceApplication;
	}

	public List<SourceEntityVO> getSourceVOList() {
		return sourceVOList;
	}

	public void setSourceVOList(List<SourceEntityVO> sourceVOList) {
		this.sourceVOList = sourceVOList;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getWebTyle() {
		return webTyle;
	}

	public void setWebTyle(String webTyle) {
		this.webTyle = webTyle;
	}

	public String getCrawlStatus() {
		return crawlStatus;
	}

	public void setCrawlStatus(String crawlStatus) {
		this.crawlStatus = crawlStatus;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public List<PortEntityVO> getPortVOList() {
		return portVOList;
	}

	public void setPortVOList(List<PortEntityVO> portVOList) {
		this.portVOList = portVOList;
	}

	public File getFileText() {
		return fileText;
	}

	public void setFileText(File fileText) {
		this.fileText = fileText;
	}

	public String getImageFileName() {
		return imageFileName;
	}

	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}

	public String getImageContentType() {
		return imageContentType;
	}

	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}

	public String getTimeGap() {
		return timeGap;
	}

	public void setTimeGap(String timeGap) {
		this.timeGap = timeGap;
	}

	public String getIsReturn() {
		return isReturn;
	}

	public void setIsReturn(String isReturn) {
		this.isReturn = isReturn;
	}

	public String getReturnDateScope() {
		return returnDateScope;
	}

	public void setReturnDateScope(String returnDateScope) {
		this.returnDateScope = returnDateScope;
	}

	public String getTakeoffJson() {
		return takeoffJson;
	}

	public void setTakeoffJson(String takeoffJson) {
		this.takeoffJson = takeoffJson;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
    
	public List<SourceTempVO> getSourceTempList() {
		return sourceTempList;
	}

	public void setSourceTempList(List<SourceTempVO> sourceTempList) {
		this.sourceTempList = sourceTempList;
	}
	
    
	

	public String getFromDateNumberString() {
		return fromDateNumberString;
	}

	public void setFromDateNumberString(String fromDateNumberString) {
		this.fromDateNumberString = fromDateNumberString;
	}

	public String getToDateNumberString() {
		return toDateNumberString;
	}

	public void setToDateNumberString(String toDateNumberString) {
		this.toDateNumberString = toDateNumberString;
	}

	public String getFrequenceString() {
		return frequenceString;
	}
	
	public String getHfromCity() {
		return hfromCity;
	}
	
	public String getGrabChannelId() {
		return grabChannelId;
	}

	public void setGrabChannelId(String grabChannelId) {
		this.grabChannelId = grabChannelId;
	}

	public void setHfromCity(String hfromCity) {
		this.hfromCity = hfromCity;
	}

	public String getHtoCity() {
		return htoCity;
	}

	public void setHtoCity(String htoCity) {
		this.htoCity = htoCity;
	}

	public void setFrequenceString(String frequenceString) {
		this.frequenceString = frequenceString;
	}

	public String getIsUpdate() {
		return isUpdate;
	}

	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}

	public String getCheckboxs() {
		return checkboxs;
	}

	public void setCheckboxs(String checkboxs) {
		this.checkboxs = checkboxs;
	}
	
	

	public String getAssignList() {
		return assignList;
	}

	public void setAssignList(String assignList) {
		this.assignList = assignList;
	}

	/**
	 * @author zengxiangqi 416428406@qq.com
	 * @throws IOException 
	 * @throws JsonMappingException 
	 * @throws JsonGenerationException 
	 */
	public void findExistCompanyByLine() throws JsonGenerationException, JsonMappingException, IOException{
		//List<SourceEntityVO> voList 
		sourceTempList = new ArrayList<SourceTempVO>();
		//根据出发地和目的地查询存在航线的公司，使用group by
		List<SourceEntityVO> tempList = sourceApplication.findSourceEntityListByLine(fromCity, toCity);
		//根据carrierKey找出公司信息
		for (Iterator iterator = tempList.iterator(); iterator.hasNext();) {
			SourceEntityVO sourceEntityVO = (SourceEntityVO) iterator.next();
			sourceTempList.add(sourceApplication.findSourceEntityListByCarrierKey(sourceEntityVO.getCarrierKey()).get(0));		
		}
		try {
			String jsonString = JsonUtil.toJson(sourceTempList);
			super.toJSONOut(jsonString);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public void checkTaskInfoEntity() throws JsonGenerationException, JsonMappingException, IOException{
		try {
			if(StringUtils.isNotEmpty(this.fromCity)&&StringUtils.isNotEmpty(this.toCity)&&StringUtils.isNotEmpty(this.grabChannel)){
				String[] keys = grabChannel.split(";");
				List<SourceEntityVO> voList = new ArrayList<SourceEntityVO>();
				for (String hbaseKey : keys) {
					boolean exist = taskInfoApplication.existTask(this.fromCity, this.toCity, hbaseKey);
					if(exist){
						voList.add(sourceApplication.findByHbaseKey(hbaseKey));
						//com.kit.utils.JsonUtil.toJSONOut(this.baseKey);
					}		
				}
				if(null!=voList&&voList.size()>0){
					super.toJSONOut(JsonUtil.toJson(voList));
				}else if(voList.size()==0){
					SourceEntityVO temp = new SourceEntityVO();
					temp.setShortName("OK");
					voList.add(temp);
					super.toJSONOut(JsonUtil.toJson(voList));
				//response.getWriter().write("OK");
				}
				
				
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
		
		
	
	}
	private int page;
	public void  pageJson() throws IOException{
		int currentPage=page;
		try {
			init();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 航班天数
		Integer grabsope = 0;
		String fromCityStr = "";
		String toCityStr = "";
		Date validityFrom =null;
		if (StringAndDateAndFileUtil.checkString(validityFromStr) && !"undefined".equalsIgnoreCase(validityFromStr)) {
			try {
				validityFrom = StringAndDateAndFileUtil.formatDateString(validityFromStr, "yyyy-MM-dd");
			} catch (ParseException e) {
				e.printStackTrace();
			}
		} 
		
		/*if (StringAndDateAndFileUtil.checkString(formDateNumber) && StringAndDateAndFileUtil.checkString(toDateNumber)) {
			grabsope = Integer.parseInt(toDateNumber) - Integer.parseInt(formDateNumber);
		}*/
//		if (formDateNumber==null ||formDateNumber.trim().equals("")) {
//			formDateNumber="0";
//		}
//		if ( toDateNumber==null||toDateNumber.trim().equals("")) {
//			toDateNumber="0";
//		}
		
		if(fromCity==null||fromCity.trim().equals("中文/拼音")){
			fromCity = "";
		}
		if(toCity==null||toCity.trim().equals("中文/拼音")){
			toCity = "";
		}
		
		if (StringAndDateAndFileUtil.checkString(fromCity)) {
			//返回航段
			PortEntityVO vo = portApplication.findPortEntityByCityName(fromCity);
			if(vo != null){
				fromCityStr = vo.getPortCode();
			}
		}
		if (StringAndDateAndFileUtil.checkString(toCity)) {
			//返回航段
			PortEntityVO vo2 = portApplication.findPortEntityByCityName(toCity);
			if(vo2 != null){
				toCityStr = vo2.getPortCode();
			}
		}
		if(StringAndDateAndFileUtil.checkString(grabChannel2)){
			grabChannel = grabChannel2;
			if(grabChannel2.equals("all")){
				grabChannel=null;
			}
			
		}else{
			if(StringAndDateAndFileUtil.checkString(grabChannel)){
				grabChannel2 = grabChannel;
			}
		}

		Page<TaskInfoEntityVO> all =taskInfoApplication.pageFindaskInfoEntityVOCriteriaList(grabChannel, fromCityStr, toCityStr, 0, 0, validityFrom, currentPage, pageSize);
		JSONObject tjson = new JSONObject();
		tjson.put("Rows", all.getResult());
		tjson.put("start", page * pageSize - pageSize);
		tjson.put("limit", pageSize);
		tjson.put("Total", all.getTotalCount());
		ServletActionContext.getResponse().setContentType("utf-8");
		ServletActionContext.getResponse().getWriter().write(tjson.toString());
		
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public PageComponent getPageComponent() {
		return pageComponent;
	}

	public void setPageComponent(PageComponent pageComponent) {
		this.pageComponent = pageComponent;
	}

	public int getCurrentPageNo() {
		return currentPageNo;
	}

	public void setCurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
}
